import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PmProjectMemberVO, PmProjectMemberForm, PmProjectMemberQuery } from '@/api/pm/types';

/**
 * 查询项目成员列表
 * @param query
 */
export function listProjectMember(query?: PmProjectMemberQuery): AxiosPromise<PmProjectMemberVO[]> {
  return request({
    url: '/pm/project/member/list',
    method: 'get',
    params: query
  });
}

/**
 * 查询项目成员详细
 * @param memberId
 */
export function getProjectMember(memberId: string | number): AxiosPromise<PmProjectMemberVO> {
  return request({
    url: '/pm/project/member/' + memberId,
    method: 'get'
  });
}

/**
 * 新增项目成员
 * @param data
 */
export function addProjectMember(data: PmProjectMemberForm): AxiosPromise<void> {
  return request({
    url: '/pm/project/member',
    method: 'post',
    data: data
  });
}

/**
 * 修改项目成员
 * @param data
 */
export function updateProjectMember(data: PmProjectMemberForm): AxiosPromise<void> {
  return request({
    url: '/pm/project/member',
    method: 'put',
    data: data
  });
}

/**
 * 删除项目成员
 * @param memberId
 */
export function delProjectMember(memberId: string | number | Array<string | number>): AxiosPromise<void> {
  return request({
    url: '/pm/project/member/' + memberId,
    method: 'delete'
  });
}

/**
 * 根据项目ID查询成员列表
 * @param projectId
 */
export function getProjectMembersByProjectId(projectId: string | number): AxiosPromise<PmProjectMemberVO[]> {
  return request({
    url: '/pm/project/member/project/' + projectId,
    method: 'get'
  });
}

/**
 * 根据用户ID查询参与的项目列表
 * @param userId
 */
export function getProjectMembersByUserId(userId: string | number): AxiosPromise<PmProjectMemberVO[]> {
  return request({
    url: '/pm/project/member/user/' + userId,
    method: 'get'
  });
}
